<?php

namespace JsonLowCode\Table\Column;

use JsonLowCode\UI;
use JsonLowCode\Table\BaseColumn;

/**
 * 单元表格标签渲染
 */
class Tag extends BaseColumn
{
    protected string $type;

    /**
     * @param ...$parameters
     */
    public function __construct(...$parameters)
    {
        parent::__construct($parameters);
        $this->type = is_string($parameters[0])?$parameters[0]:"primary";
    }

    protected function booted(): void
    {
        $this->element = UI::tag();
        $this->element->class("m-1");
        $this->element->type($this->type);
        if ($this->isLoop){
            $itemKey = $this->loopArgs[0];
            $indexKey = $this->loopArgs[1];
            $this->element->loopArgs($itemKey,$indexKey);
            $this->element->loop($this->getColumnKey(),true);
            $this->children($this->getLoopValueExpression());
        }else{
            $this->children($this->getNormalValueExpression());
        }
        if ($this->isColor()){
            $this->element->type($this->getColorBindKey(),true);
        }
    }


}
